home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2 Examples.sit / Raven 1.2 Examples / Quill / Source / ResourceInfoDialog.cpp < prev    next >
C/C++ Source or Header  |  1997-08-26  |  5KB  |  182 lines

  1. /*
  2.  *    File:        ResourceInfoDialog.cpp
  3.  *    Function:    A dialog that allows the user to change a resource's id and name.
  4.  *    Written by:    Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *    Change History (most recent first):
  10.  *
  11.  *         <->     8/11/96    JDJ        Created
  12.  */
  13.  
  14. #include "ResourceInfoDialog.h"
  15.  
  16. #include <ZApplication.h>
  17. #include <ZBehaviors.h>
  18. #include <ZDialogHandler.h>
  19. #include <ZDialogUtils.h>
  20. #include <ZExceptions.h>
  21. #include <ZIntConversions.h>
  22. #include <ZStaticText.h>
  23. #include <ZStringUtils.h>
  24. #include <ZTextBox.h>
  25.  
  26. #include "DialogBoxProxy.h"
  27. #include "WindowProxy.h"
  28.  
  29.  
  30. // ===================================================================================
  31. //    class CResourceInfoDialog
  32. // ===================================================================================
  33.  
  34. static TReanimatorRegister<CResourceInfoDialog> sResourceInfoRegistrar;
  35.  
  36. //---------------------------------------------------------------
  37. //
  38. // CResourceInfoDialog::~CResourceInfoDialog
  39. //
  40. //---------------------------------------------------------------
  41. CResourceInfoDialog::~CResourceInfoDialog()
  42. {
  43. }
  44.  
  45.  
  46. //---------------------------------------------------------------
  47. //
  48. // CResourceInfoDialog::CResourceInfoDialog
  49. //
  50. //---------------------------------------------------------------
  51. CResourceInfoDialog::CResourceInfoDialog()
  52. {
  53.     mRsrcMap = nil;
  54.     
  55.     mNameField = nil;
  56.     mIdField   = nil;
  57. }
  58.  
  59.  
  60. //---------------------------------------------------------------
  61. //
  62. // CResourceInfoDialog::Create (MReanimatable*)            [static]
  63. //
  64. //---------------------------------------------------------------
  65. MReanimatable* CResourceInfoDialog::Create(MReanimatable* parent)
  66. {
  67.     ASSERT(parent == nil);
  68.     
  69.     if (CWindowProxy::msUseProxy)
  70.         return CDialogBoxProxy::Create(parent);
  71.     else
  72.         return new CResourceInfoDialog;
  73. }
  74.  
  75.  
  76. //---------------------------------------------------------------
  77. //
  78. // CResourceInfoDialog::Pose
  79. //
  80. //---------------------------------------------------------------
  81. bool CResourceInfoDialog::Pose(CResourceMap* rsrcMap, const SResource& oldInfo, SResource* newInfo)
  82. {
  83.     ASSERT(rsrcMap != nil);
  84.     ASSERT(newInfo != nil);
  85.     
  86.     CResourceInfoDialog* dialog = dynamic_cast<CResourceInfoDialog*>(TDialogBox::Create(202, TApplication::Instance()));
  87.     dialog->SetData(rsrcMap, oldInfo);
  88.     
  89.     string message = kNothingMessage;
  90.                 
  91.     {
  92.     TDialogHandler handler(dialog);
  93.         dialog->Show();
  94.                 
  95.         while (message != kCancelMessage && message != kOKMessage) {
  96.             message = handler.ProcessNextEvent();
  97.             
  98.             if (message == kOKMessage && !dialog->Validate())
  99.                 message = kNothingMessage;
  100.         }
  101.     }
  102.     
  103.     if (message == kOKMessage)
  104.         *newInfo = dialog->GetData();
  105.     
  106.     return message == kOKMessage;
  107. }
  108.  
  109.  
  110. //---------------------------------------------------------------
  111. //
  112. // CResourceInfoDialog::Validate
  113. //
  114. //---------------------------------------------------------------
  115. bool CResourceInfoDialog::Validate() const
  116. {
  117.     bool valid = Inherited::Validate();
  118.     
  119.     if (valid) {
  120.         long id = mIdField->GetValue();
  121.  
  122.         if (id != mOldInfo.id && mRsrcMap->HasResource(id)) {
  123.             DoStop(LoadAppString("Couldn't set the resource id."), LoadAppString("There's already a resource with this id!"));
  124.             
  125.             valid = false;
  126.         }
  127.     }
  128.     
  129.     return valid;
  130. }
  131.  
  132.  
  133. //---------------------------------------------------------------
  134. //
  135. // CResourceInfoDialog::OnReanimated
  136. //
  137. //---------------------------------------------------------------
  138. void CResourceInfoDialog::OnReanimated()
  139. {
  140.     Inherited::OnReanimated();
  141.     
  142.     mIdField = dynamic_cast<TTextBox*>(this->FindSubPane("ID EditBox"));
  143.     
  144.     mNameField = dynamic_cast<TTextBox*>(this->FindSubPane("Name EditBox"));    
  145.     this->SetLatentTarget(mNameField);
  146. }
  147.  
  148.  
  149. //---------------------------------------------------------------
  150. //
  151. // CResourceInfoDialog::SetData
  152. //
  153. //---------------------------------------------------------------
  154. void CResourceInfoDialog::SetData(CResourceMap* rsrcMap, const SResource& info)
  155. {
  156.     this->SetName(LoadIndString(257, 3) + info.name + LoadIndString(257, 4));
  157.     
  158.     mRsrcMap = rsrcMap;
  159.     mOldInfo = info;
  160.  
  161.     mIdField->SetValue(info.id);
  162.     mNameField->SetText(info.name);
  163.  
  164.     mNameField->SelectAll();
  165. }
  166.  
  167.  
  168. //---------------------------------------------------------------
  169. //
  170. // CResourceInfoDialog::GetData
  171. //
  172. //---------------------------------------------------------------
  173. SResource CResourceInfoDialog::GetData() const
  174. {
  175.     ResID id    = mIdField->GetValue();
  176.     string name = mNameField->GetText();
  177.     
  178.     return SResource(id, name, THandle());
  179. }
  180.  
  181.  
  182.